<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/axios.js"></script>
    <link rel="stylesheet" href="./css/index.css">
    <link rel="stylesheet" href="./css/reset.css">
</head>
<body>
    <ul class="h1">
        <!-- <li>
            <h1></h1>
            <p></p>
            <button>加入购物车</button>
            <img src="" alt="">
            
            

        </li> -->
        </ul>
    <script>
        console.log(location.search);
        let obj=new URLSearchParams(location.search)
        console.log(obj);
        console.log(obj.get("pid"));
        let pid=obj.get("pid")
        let url="http://jx.xuzhixiang.top/ap/api/detail.php"
        axios.get(url,{params:{id:pid}}).then((r)=>{console.log(r.data);;
        let pObj =r.data.data;
        console.log(pObj);
        let arr=
        `
        <li>
            <img src="${pObj.pimg}" alt="">
            <div class="h2">
            <p class="h3">${pObj.pname}</p>
            <p class="h5">${pObj.pdesc}</p>
            <p class="h4">${pObj.pprice}元</p>
            <div class="h6">
            <input type ="number" value ="1" min="1"
            max="5" id="pnum-ipt">
            <button onclick="addcartclick()" class="h7">加入购物车</button>
            </div>
            </div>
            
             </li>
        `
        document.querySelector("ul").innerHTML=arr
   })
   //加入购物车
   async function addcartclick(){
       let url="http://jx.xuzhixiang.top/ap/api/add-product.php";
       //请求参数
       let uid=localStorage.getItem("uid")
       let pnumIpt=document.querySelector("#pnum-ipt")
       let pnum =pnumIpt.value 
       let data={pid,uid,pnum}
       let r=await axios.get(url,{params:data})
       console.log(r.data);
       
       location.href="购物车.html"
   }
        </script>
</body>
</html>